package com.um2.simplexe.serveur.plugins.calcul3D.util;

public class Plan {

	public static int MAX_NUMERO_EXISTANT = 0;
	
	
	public static int INF_EGAL = 0;
	public static int SUP_EGAL = 0;
	
	int comparaison ;
	int numero ;
	private double A;
	private double B;
	private double C;
	private double D;
	
	
	/**
	 * on cree un plan,
	 * avec un numero de plan unique.
	 * AX1 + BX2 + CX3 conparaison D
	 * @throws Exception 
	 */
	public Plan(double A,double B,double C,int Comparaison,double D) throws Exception {
		this.comparaison = Comparaison ;
		this.numero = Plan.MAX_NUMERO_EXISTANT+1 ;
		Plan.MAX_NUMERO_EXISTANT = Plan.MAX_NUMERO_EXISTANT +1 ;
		
		
		if (Double.isNaN(A) || Double.isNaN(B) || Double.isNaN(C) || Double.isNaN(D))
		{
			throw new Exception ("impossible de creer le plan, valeurs incorrectes .") ;
		}

		
		this.A = A ;
		this.B = B ;
		this.C = C ;
		this.D = D ;
	}
	
	
	
	
	public double getA() {
		return A;
	}




	public double getB() {
		return B;
	}




	public Double getC() {
		return C;
	}


	public Double getD() {
		return D;
	}

	public int getComparaison() {
		return (this.comparaison) ;
	}
	
	
	
	public int getNumero() {
		return this.numero ; 
	}

	public String toString()
	{
		return "Plan:"+this.getNumero()+": ["+this.getA()+"X1 + "+this.getB()+"X2 + "+this.getC()+"X3 = "+this.getD()+"]" ;
	}

	public boolean lePointRespecteLOptimum(Point aTester) throws Exception {
		if (this.getComparaison()==Plan.INF_EGAL) {
			return  (this.getA()*aTester.getX()+this.getB()*aTester.getY()+this.getC()*aTester.getZ()<=this.getD()) ;
		}
		if (this.getComparaison()==Plan.SUP_EGAL) {
			return  (this.getA()*aTester.getX()+this.getB()*aTester.getY()+this.getC()*aTester.getZ()>=this.getD()) ;
		}
		throw new Exception ("le Point a tester par rapport au plan "+this.toString()+" n a pas de bonne comparaison") ;
	}

}
